<?php
include_once "../header1.php";
?>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function showHint(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
   var sch_id=document.forms["DelExa"]["sch_id"].value;
  str=str+","+sch_id;
xmlhttp.open("GET","upp_tea_names.php?q="+str,true);
xmlhttp.send();
}
function fill(val)
{
document.DelExa.TeaName.value=val;
document.getElementById("List").innerHTML="";
var xmlhttp;    
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("TID").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","tra_ids.php?q="+val,true);
xmlhttp.send();
}
</script>
<script type="text/javascript">
function DeleteVerification()
{
<?php
include_once ("../Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("../index.php");
}
   
   else
   {
   ?>
var Training_Id=document.forms["DelExa"]["Training_Name"].value;
var Teacher_NIC=document.forms["DelExa"]["TeaName"].value;
 
if (Training_Id=="Select One"||Teacher_NIC=="" )
  {
  alert("Please select the Training Id and Teacher's name to delete!");
  return false;
  }
  
if (Training_Id!="Select One"&&Teacher_NIC!="" )
{
var r=confirm("Are you sure to delete this?");
if (r==true)
  {
  return true;
 
 }

if(r==false)
  {
 return false;
  }
}
}
</script>
</head>
<body>
  <?php

include_once "../header2.php";


?>
<?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
<div id="lefttablereg">
<form  name="DelExa" action="#" method="POST" onSubmit="return DeleteVerification()">
<?php
if(isset($_POST['Delete']))
{
require_once 'del.php';
}
?>
  <table width="454" border="0" class="tablefontv">
    <tr>
      <td height="29" colspan="3"  scope="row" class="err">
      <?php
      if(isset($_POST['Delete']))
{
	if(isset($_SESSION['errorin']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo ($_SESSION['errorin']);
		unset($_SESSION['errorin']);
	}
	if(isset($_SESSION['error']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo ($_SESSION['error']);
		unset($_SESSION['error']);
	}
	if(isset($_SESSION['errornorow']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
	if(isset($_SESSION['errornot']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornot'];
		unset($_SESSION['errornot']);
	}
	if(isset($_SESSION['errornot2']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornot2'];
		unset($_SESSION['errornot2']);
	}
}   
?>
</td>
      </tr>
       </table>
        <table width="457" border="0" class="tablefontv">
    <tr>
      <th width="55" height="29"  scope="row" bgcolor="#6AB5FF">&nbsp;</th>
      <th width="163"  scope="row" bgcolor="#6AB5FF">Teacher's Name:</th>
      <td width="156" bgcolor="#999999">
        <?php
 $hin=$_SESSION['NIC_Number'].",".$_SESSION['Access_Type'];
		   echo "<input type='hidden' size='1' id='sch_id' name='sch_id' value='$hin'/>";
	  if(!isset($Teac_name))
	{
	  $tnam=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$Teacher_NIC'");
	  if($rot=mysql_fetch_array($tnam))
	  {
	  $Teac_name=$rot['First_Name']." ".$rot['Last_Name'];
	  }
	  }	
	  echo "<input type='text' id='TeaName' name='TeaName' onKeyUp='showHint(this.value)' value='$Teac_name' onClick='cleartbox()' size='35'/>";
	  ?></td>
      <td width="65" bgcolor="#6AB5FF">&nbsp;</td>
    </tr>
    <tr>
      <th height="30" bgcolor="#6AB5FF" scope="row">&nbsp;</th>
      <th height="30" bgcolor="#6AB5FF" scope="row">Training Name:</th>
      <td bgcolor="#999999"><div id="TID"><select name="Training_Name">
        <?php
	  
	  if(isset($_POST['Delete']))
	  {
	$resultnet=mysql_query("SELECT * FROM training WHERE Training_Id='$Training_Id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$Training_Name=$rownet['Training_Name'];
}
echo '<option value="'.$Training_Name.'">'.$Training_Name.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  
	   if($Teacher_NIC!="")
	  {
	  $exa=mysql_query("SELECT DISTINCT(Training_Id) FROM training_details WHERE Teacher_NIC='$Teacher_NIC'");
	  }
	  if($Teacher_NIC=="")
	  {
	  $exa=mysql_query("SELECT DISTINCT(Training_Id) FROM training_details");
	  }
  while($row=mysql_fetch_array($exa))
  {
	 $Tra_Id=$row['Training_Id'];
	 $resultnet=mysql_query("SELECT * FROM training WHERE Training_Id='$Tra_Id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$Tra_Name=$rownet['Training_Name'];
}
	if($Training_Name!=$Tra_Name)
{
	  echo '<option value="'.$Tra_Name.'">'.$Tra_Name.'</option>';
  }
  }
	  ?>
      </select></div></td>
      <td bgcolor="#6AB5FF">&nbsp;</td>
    </tr>
     
  </table>

  <br/>
      <a href="deletetra.php" class="reset">Reset</a>|
    <input name="Delete" align="middle" type="submit" value="Delete" class="buttonok"/>
 <br/>
   </form>
  <?php
   	   if(isset($_POST['Delete']))
{
    
if($_SESSION['Access_Type']=="Administrator"||$_SESSION['Access_Type']=="Teacher in Charge")
   {
if($Training_Id!=""&&$Teacher_NIC!=""&&$Duration!=""&&$Training_Name!="")
   {
   echo '<table width="458" border="0" class="tablefontv">';
         echo '<tr>';
        echo '<th width="200" height="44" scope="row">';
		echo "Training Id:";
		echo '</th>';
        echo '<td width="144">';
		echo $Training_Id;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Teacher NIC:";
		echo '</th>';
        echo '<td>';
		echo $Teacher_NIC;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Training Name:";
		echo '</th>';
        echo '<td>';
		echo $Training_Name;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Duration :";
		echo '</th>';
       echo '<td>';
	   echo $Duration;
	   echo '</td>';
      echo '</tr>';
         echo '</table>';
	}
	}	
	}
    ?>
</div>
 <div id="righttablereg">
  <div class="suggestionListsch" id="List"></div>
 </div>
</div>
</div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">TRAINING DETAILS</h2>
            </div> 
<?php
include_once "menu.php";
?>
<?php
include_once "../footer.php";
?>
<?php
	  }
  
?>
</body>
</html>